package com.example.japinhands.ui.screen

import androidx.compose.foundation.clickable
import androidx.compose.foundation.layout.ExperimentalLayoutApi
import androidx.compose.foundation.layout.FlowRow
import androidx.compose.foundation.layout.fillMaxWidth
import androidx.compose.foundation.layout.padding
import androidx.compose.foundation.lazy.LazyColumn
import androidx.compose.material3.Text
import androidx.compose.runtime.Composable
import androidx.compose.runtime.LaunchedEffect
import androidx.compose.runtime.mutableStateListOf
import androidx.compose.runtime.remember
import androidx.compose.ui.Modifier
import androidx.compose.ui.unit.dp
import androidx.compose.ui.unit.sp
import com.example.japinhands.JApplication
import com.example.japinhands.JapViewModel
import com.example.japinhands.data.DeformAdj
import kotlin.concurrent.thread

@OptIn(ExperimentalLayoutApi::class)
@Composable
fun ManageDeformAdjScreen(
    viewModel: JapViewModel
) {
    val tag = "ManageDeformAdj"
    val deforms = remember {
        mutableStateListOf<DeformAdj>()
    }
    LaunchedEffect(Unit) {
        thread {
            deforms.addAll(viewModel.getAllDeformAdj())
        }
    }
    LazyColumn {
        deforms.forEach {
            item {
                FlowRow(
                    modifier = Modifier
                        .fillMaxWidth()
                        .clickable {
                            JApplication.showToast("You clicked ${it.deform1}")
                        }
                ) {
                    Text(
                        text = it.deform1,
                        modifier = Modifier.padding(8.dp),
                        fontSize = 25.sp
                    )
                    Text(
                        text = it.deform2,
                        modifier = Modifier.padding(8.dp),
                        fontSize = 25.sp
                    )
                    Text(
                        text = it.deform3,
                        modifier = Modifier.padding(8.dp),
                        fontSize = 25.sp
                    )
                    Text(
                        text = it.deform4,
                        modifier = Modifier.padding(8.dp),
                        fontSize = 25.sp
                    )
                }
                }
            }

    }
}